package net.common.util;

import java.io.File;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

/**
 * Jar文件处理工具
 * 
 * @author 孙树林
 * 
 */
public class JarUtils {

	/**
	 * Jar搜索
	 * 
	 * @throws Exception
	 */
	public static List<String> searchByJar(File file, String partten) throws Exception {
		List<String> files = new ArrayList<String>();
		Enumeration<JarEntry> jarEntrys = new JarFile(file).entries();
		while (jarEntrys.hasMoreElements()) {
			JarEntry jar = jarEntrys.nextElement();
			String fullName = jar.getName();
			int end = fullName.lastIndexOf("/");
			String fileName = null;
			if (end != -1) {
				fileName = fullName.substring(end + 1);
			} else {
				fileName = fullName;
			}
			if (StringUtils.match(fileName, partten) && !fileName.endsWith("struts-default.xml")) {
				files.add(fullName);
			}
		}
		return files;
	}

}
